import { View } from "../../../../mvc/core/View";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Language } from "../../../../../extend/language/Language";
import { SWFInfo } from "../../../../../com/gengine/resource/info/SWFInfo";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ObjCreate } from "../ObjCreate";
import { FontUtil } from "../../../../common/font/FontUtil";
import { StaticResUrl } from "../../../resource/StaticResUrl";
import { Global } from "../../../../../com/gengine/global/Global";
import { SoundManager } from "../../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../../common/sound/SoundTypeConst";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class DialogBase
    
    export  class DialogBase extends View
    {
        constructor()
        {
            super();
            this._stagerect = new Object /* flash.geom.Rectangle */();
            this.initUI();
            return;
        }

        public set dialogName(arg1: string)
        {
            this._npcNameTxt.htmlText = HTMLUtil.addColor(arg1, "#FFFF00");
            return;
        }

        public set dialogHead(arg1: string)
        {
            this._headURL = arg1;
            LoaderManager.instance.load(this._headURL, this.onNpcHeadLoaded, 3, this._headURL);
            return;
        }

        public set title(arg1: string)
        {
            this._titleText.htmlText = arg1;
            return;
        }

        public set desc(arg1: string)
        {
            this._descText.htmlText = arg1;
            return;
        }

        protected onDialogOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            this.optReq(loc1.label);
            return;
        }

        protected optReq(arg1: string): void
        {
            if (flash.utils.getTimer() - this._optTimer <= 250) 
            {
                return;
            }
            this._optTimer = flash.utils.getTimer();
            var loc1=arg1;
            switch (loc1) 
            {
                case Language.getString(20025):
                {
                    this.hide();
                    return;
                }
            }
            return;
        }

        protected onNpcHeadLoaded(arg1: SWFInfo): void
        {
            if (arg1 && arg1.clip) 
            {
                if (arg1.extData == this._headURL) 
                {
                    if (this._npcHeadmc && this._npcHeadBg.contains(this._npcHeadmc)) 
                    {
                        this._npcHeadBg.removeChild(this._npcHeadmc);
                    }
                    this._npcHeadmc = arg1.clip;
                    this._npcHeadBg.addChild(this._npcHeadmc);
                    this._npcHeadmc.x = (this.width - 410 - this._npcHeadmc.width) / 2;
                    this._npcHeadmc.y = this.height - this._npcHeadmc.height - 35;
                }
            }
            return;
        }

        protected initUI(): void
        {
            this._npcNameTxt = new Object /* flash.text.TextField */();
            this._npcNameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            var loc1=new GTextFormat("", 14, 16776960);
            loc1.leading = 1;
            this._npcNameTxt.defaultTextFormat = loc1;
            this._npcNameTxt.width = 150;
            this._npcNameTxt.x = 90;
            this._npcNameTxt.y = this.height - 30;
            this._npcNameTxt.mouseEnabled = false;
            this._npcNameTxt.textColor = 16776960;
            this._npcNameTxt.htmlText = HTMLUtil.addColor("...", "#ffff00");
            this._npcNameTxt.filters = [FilterConst.nameGlowFilter];
            addChild(this._npcNameTxt);
            this._npcHeadBg = new Object /* flash.display.Sprite */();
            this._npcHeadBg.mouseChildren = false;
            this._npcHeadBg.mouseEnabled = false;
            addChild(this._npcHeadBg);
            this._dialogOpt = new GButton();
            this._dialogOpt.styleName = "DialogOptBtn";
            this._dialogOpt.setSize(75, 25);
            this._dialogOpt.x = this.width - this._dialogOpt.width - 25;
            this._dialogOpt.y = this.height - this._dialogOpt.height - 10;
            this._dialogOpt.textField.filters = [FilterConst.nameGlowFilter];
            this._dialogOpt.addEventListener(flash.events.MouseEvent.CLICK, this.onDialogOptBtnClickHandler);
            this._dialogOpt.label = Language.getString(20025);
            addChild(this._dialogOpt);
            this._titleText = ObjCreate.createGTextField("", 200, 25, 360, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16776960, true, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._descText = ObjCreate.createGTextField("", 200, 50, 360, 200, this);
            this._descText.wordWrap = true;
            this._descText.multiline = true;
            this._descText.mouseWheelEnabled = false;
            this._descText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._closeBtn = new GButton();
            this._closeBtn.setSize(19, 19);
            this._closeBtn.label = "";
            this._closeBtn.styleName = "CloseButton";
            this._closeBtn.x = this.width - this._closeBtn.width - 4;
            this._closeBtn.y = 4;
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeBtnClickHandler);
            addChild(this._closeBtn);
            this.loadBg();
            return;
        }

        protected loadBg(): void
        {
            LoaderManager.instance.load(StaticResUrl.DialogBg, this.onDialogBgLoaded, 0);
            return;
        }

        protected onDialogBgLoaded(arg1: SWFInfo): void
        {
            if (arg1) 
            {
                this._dialogBg = arg1.clip;
            }
            if (this._dialogBg) 
            {
                if (!contains(this._dialogBg)) 
                {
                    this.addChildAt(this._dialogBg, 0);
                }
            }
            return;
        }

        protected closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.focus = Global.stage;
            SoundManager.instance.soundPlay(SoundTypeConst.UIclose);
            this.hide();
            return;
        }

        protected onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target is flash.display.Sprite && !(arg1.target is GButton)) 
            {
                Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
                this._stagerect.x = 0;
                this._stagerect.y = 0;
                this._stagerect.width = this.stage.stageWidth;
                this._stagerect.height = this.stage.stageHeight;
                this.startDrag(false, this._stagerect);
            }
            return;
        }

        protected onMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            this.stopDrag();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            if (_layer) 
            {
                if (_isHide) 
                {
                    _isHide = false;
                    _layer.addPopUp(this);
                    this.dispatchEvent(new WindowEvent(WindowEvent.SHOW));
                }
                else 
                {
                    _layer.setTop(this);
                }
                if (!(arg1 == 0) && !(arg2 == 0)) 
                {
                    _layer.setPosition(this, arg1, arg2);
                }
                else 
                {
                    _layer.setPosition(this, (Global.stage.stageWidth - this.width) / 2, Global.stage.stageHeight / 2 - 50);
                }
                if (this._dialogBg) 
                {
                    if (!contains(this._dialogBg)) 
                    {
                        this.addChildAt(this._dialogBg, 0);
                    }
                }
            }
            return;
        }

        public /* override */ hide(): void
        {
            if (_layer && !_isHide) 
            {
                this.stopDrag();
                Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
                _isHide = true;
                _layer.removePopup(this);
                this.dispatchEvent(new WindowEvent(WindowEvent.CLOSE));
            }
            return;
        }

        public /* override */ get height(): number
        {
            return 161;
        }

        public /* override */ get width(): number
        {
            return 597;
        }

        public /* override */ set layer(arg1: ILayer)
        {
            _layer = arg1;
            return;
        }

        public /* override */ get layer(): ILayer
        {
            return _layer;
        }

        protected /* var */_closeBtn: GButton;

        protected /* var */_dialogBg: Object /* flash.display.MovieClip */;

        protected /* var */_headURL: string;

        protected /* var */_npcHeadBg: Object /* flash.display.Sprite */;

        protected /* var */_npcHeadmc: Object /* flash.display.MovieClip */;

        protected /* var */_npcNameTxt: Object /* flash.text.TextField */;

        protected /* var */_titleText: GTextFiled;

        protected /* var */_descText: GTextFiled;

        protected /* var */_dialogOpt: GButton;

        protected /* var */_optTimer: int;

        protected /* var */_stagerect: Object /* flash.geom.Rectangle */;
    }
